<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
	<link href="https://cdn.bootcss.com/animate.css/3.7.2/animate.css" rel="stylesheet">
	<style>
		.v-enter,.v-leave-to{
			opacity: 0
		}
		.v-enter-active,.v-leave-active{
			transition: opacity 1s;
			}		}
	</style>
</head>
<body>
	<div id="root">
		<!-- name对应style里的前缀 -->
		<fade :show="show">
			<div >Hello world</div>
		</fade>	

		<fade :show="show">
			<h1 >Hello world</h1>
		</fade>		

		<button @click="handleClick">切换</button>
	</div>
	<script type="text/javascript">
	// 使用组件封装常用动画
	Vue.component('fade',{
		props:['show'],
		template:`
			<transition @before-enter="handleBeforeEnter"
			@enter="handleEnter">
				<slot v-if="show"></slot>
			</transition>
		`,
		methods:{
			handleBeforeEnter:function(el){
				el.style.color='red'
			},
			handleEnter:function(el,done){
				setTimeout(()=>{
					el.style.color='green'
					done()
				},2000)
			}
		}
	})
		var vm=new Vue({
			el:"#root",
			data:{
				show:true
			},
			methods:{
				handleClick:function(){
					this.show=!this.show
				}
			}
		})
	
	</script>
</body>
</html>